package com.xing.crm.service.impl;

import com.xing.crm.mapper.UserMapper;
import com.xing.crm.pojo.User;
import com.xing.crm.service.UserService;
import com.xing.crm.utils.MD5Util;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Mr.L
 * @version V1.0
 * @date 2021年07月21日 17:37
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User checkLogin(String account, String password) {
        return userMapper.checkLogin(account, MD5Util.stringMD5(password));
    }
    
    @Override
    public Map<String, Object> updatePwd(User user) {
        Map<String, Object> result = new HashMap(0);
        result.put("code", 0);
        result.put("data", null);
        String msg = "操作失败";
        if(!StringUtils.isEmpty(user.getPassword())) {
            String pwd = MD5Util.stringMD5(user.getPassword());
            user.setPassword(pwd);
            if(userMapper.updatePwd(user) > 0) {
                result.put("data", user);
            }
            msg = "执行成功";
        }
        result.put("msg", msg);
        return result;
    }
}

